#include "fs/fs.h"
#include "fs/inode.h"
#include "fs/dentry.h"
#include "kernel/slab.h"

// global variables
listnode_t fs_object_list = LISTNODE_INITIALIZER(fs_object_list);

int _fs_create(fs_object_t* fsobject, uchar* name,
		dentry_operations_t *dops, inode_operations_t* iops)
{
	qstr_t fsname;
	dentry_t *tmp;
	kassert(NULL != fsobject && NULL != name \
		&& NULL != dops && NULL != iops);

	fsname.str = name;
	fsname.size = strlen(name);
	tmp = dalloc(&fsname, dops);
	if (NULL == tmp)
		return ERR_NOMEMORY;

	fsobject->root = tmp;
	tmp->ops = dops;
	fsobject->dops = dops;
	listnode_add(fs_object_list, fsobject->ownerlist);

	return 0;
}

fs_object_t* fs_create(uchar* name, dentry_operations_t *dops,
				inode_operations_t* iops)
{
	fs_object_t* ret;

	if (NULL == name || NULL == dops || NULL == iops)
		return NULL;

	ret = kmalloc(sizeof(fs_object_t));
	if (NULL == ret) return NULL;

	if (_fs_create(ret, name, dops, iops))
	{
		kfree(ret);
		return NULL;
	}
	return ret;
}

void global_init_mount_module(void)
{
}
/* EOF */
